package org.dentalcard.ui.schedule.tools;

import org.dentalcard.ui.api.tools.AbstractDecTableModel;

import java.awt.*;
import java.text.DateFormat;
import java.util.*;
import java.util.List;

/**
 * @user: Vladimir Chernishov
 * @date: 25.12.11
 * @time: 18:02
 */
public class WorkScheduleModel extends AbstractDecTableModel {

    private static String[] days = new String[]{"MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"};
    
    private List<List<WorkScheduleDay>> data = new ArrayList<List<WorkScheduleDay>>();

    public WorkScheduleModel() {
        super(days);
        data.add(new ArrayList<WorkScheduleDay>());
    }

    @Override
    public int getRowCount() {
        return data.size();
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        List<WorkScheduleDay> week = data.get(rowIndex);
        if(week.size() < (columnIndex - 1)){
            return "";
        } else {
            if(week.size() < (columnIndex + 1)){
                return "";
            }
            return week.get(columnIndex);
        }
        
    }

    public void addWorkDay(WorkScheduleDay workScheduleDay) {
        List<WorkScheduleDay> week = data.get(data.size() - 1);
        if(week.size() >= 7){
            List<WorkScheduleDay> newWeek = new ArrayList<WorkScheduleDay>();
            newWeek.add(workScheduleDay);
            data.add(newWeek);
        } else {
            week.add(workScheduleDay);
        }
    }
}
